#define _CRT_SECURE_NO_WARNINGS 1
#include <climits>
#include <iostream>
#include <set>
#include <string>
using namespace std;

int main()
{
    string s;
    cin >> s;
    set<char> se;
    for (auto& a : s)
    {
        se.insert(a);
    }
    int Min = INT_MAX;
    for (auto& a : se)
    {
        cerr << a << endl;
        int count = 0;
        for (int i = 0;i < s.size();i++)
        {
            //cerr<<s[i]<<":";
            int x = s[i] - a >= 0 ? s[i] - a : s[i] - a + 26;
            int y = 26 - x;
            //cerr<<x<<","<<y<<";";
            count += min(x, y);
            //cerr<<count<<endl;
        }
        Min = min(Min, count);
    }
    cout << Min << endl;
}
